#include  <cstdio>
#include  <algorithm>
#include  <functional>
#include  <string>
#include  <iostream>
using namespace std;

int main(int argc, char *argv[])
{
	string ss;
	int str[26];
	int t;
	scanf("%d",&t);
	while( t!=0 )
	{
		cin >> ss;

		for( int i = 0; i < ss.size() ;++i   )
		{
			str[i] = (int)ss[i];
			str[i] = str[i] - (int)'A'+1;
		}
		
		int n = ss.size();
		sort(str,str+n,greater<int>());
		
		int a,b,c,d,e;
		for( a = 0 ; a < n ; ++a )
		{
			for( b = 0 ; b < n ; ++b )
			{
				if(b == a)
					continue;
				for( c = 0; c < n ; ++c )
				{
					if(c == a || c == b)
						continue;
					for( d = 0; d<n ; ++d )
					{
						if(d == a || d == b || d == c)
							continue;
						for( e = 0; e < n ; ++e )
						{
							if(e==a || e==b || e==c || e==d)
								continue;
							int temp = str[a]-str[b]*str[b] + str[c]*str[c]*str[c] - 
									str[d]*str[d]*str[d]*str[d] + 
									str[e]*str[e]*str[e]*str[e]*str[e];

							if(temp == t)
							{
								printf("%c%c%c%c%c\n",str[a]+'A'-1,str[b]+'A'-1,str[c]+'A'-1,
										str[d]+'A'-1,str[e]+'A'-1);
								goto end;
							}
						}
					}
				}
			}
		}
		printf("no solution\n");
end:
		scanf("%d",&t);
	}
}
